package com.shanshan.system.controller;


import com.shanshan.system.entity.Admin;
import com.shanshan.system.service.IAdminService;
import com.shanshan.system.vo.Result;
import com.shanshan.system.vo.SearchAdmin;
import com.shanshan.system.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shanshan
 * @since 2023-01-31
 */
@RestController
@RequestMapping("/system/admin")
@Api(tags = "菜单")
public class AdminController {
    @Autowired
    private IAdminService adminService;

    @PostMapping("/accountName")
    public Result accountName(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize, @RequestBody UserVo userVo){
        return adminService.accountName(currentPage,pageSize,userVo);
    }

    /**
     * @param id:
     * @return Result
     * @description 根据用户id进行查询
     */
    @GetMapping("/selectId")
    public Result selectId(Integer id){
        return adminService.selectId(id);
    }

    /**
     * @param id:
     * @return Result
     * @description 根据部门id查询所有的用户
     */
    @GetMapping("/branchId")
    public Result branchId(Integer id){
        return adminService.branchId(id);
    }

    /**
     * @param :
     * @return Result
     * @description 得到用户的具体信息
     */
    @GetMapping("/adminMS")
    public Result admin(){
        return adminService.admin();
    }


    /**
     * @param :
     * @return Result
     * @description 修改用户密码
     */
    @PostMapping("/update")
    public Result update(@RequestBody Admin admin){
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(admin);
        return adminService.updateAdmin(admin);
    }

    /***
     * @param currentPage:
     * @param pageSize:
     * @param searchAdmin:
     * @return Result
     * @description 进行分页和条件查询
     */
    @PostMapping("/selectAdminAll")
    public Result selectAdminAll(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize, @RequestBody SearchAdmin searchAdmin){

        return adminService.selectAdminAll(currentPage,pageSize,searchAdmin);
    }

    /**
     * @param id:
     * @return Result
     * @description 删除用户
     */
    @GetMapping("/deleteAdmin")
    public Result deleteAdmin(Integer id){
        return adminService.deleteAdmin(id);
    }

    @PostMapping("/add")
    public Result addAdmin(@RequestBody Admin admin){
        return adminService.addAdmin(admin);
    }

}
